package com.zhiche.lisa.bms.service.cost.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.mysql.jdbc.StringUtils;
import com.zhiche.lisa.bms.dao.mapper.cost.CostMidMapper;
import com.zhiche.lisa.bms.dao.model.cost.CostMid;
import com.zhiche.lisa.bms.service.cost.CostMidService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 费用信息 服务实现类
 * </p>
 *
 * @author zhangkun
 * @since 2018-09-10
 */
@Service
public class CostMidServiceImpl extends ServiceImpl<CostMidMapper, CostMid> implements CostMidService {

    /**
     * 根据计费单据号查询费用信息
     *
     * @param billId
     */
    @Override
    public CostMid queryCostMidByBillId(String billId) {
        CostMid cn = new CostMid();
        Wrapper<CostMid> ew = new EntityWrapper<>();
        if (!Objects.isNull(billId) && !StringUtils.isNullOrEmpty(billId)) {
            ew.eq("bill_id", billId);
            cn = this.selectOne(ew);
        }
        return cn;
    }

    /**
     * 根据计费单据号批量查询费用信息
     *
     * @param wayBillDtlIds
     */
    @Override
    public Map<String, CostMid> queryCostMidByBillIds(List<String> wayBillDtlIds) {
        Map<String, CostMid> map = Maps.newHashMap();
        if (!CollectionUtils.isEmpty(wayBillDtlIds)) {
            List<CostMid> cn = new ArrayList<>();
            EntityWrapper ew = new EntityWrapper<>();
            if (!CollectionUtils.isEmpty(wayBillDtlIds)) {
                ew.in("bill_id", wayBillDtlIds);
                cn = this.selectList(ew);
            }
            for (int i = 0; i < cn.size(); i++) {
                map.put(cn.get(i).getBillId(), cn.get(i));
            }
        }
        return map;
    }
}
